package com.dcy.daily.skill.rabbitMQ.springAMQP.tmp.batch;

import com.dcy.daily.common.config.annotation.ComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import java.util.List;

/**
 * 接收批量消息
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年07月22日 11:14
 */
@ComponentUtil.UComponent
public class Recv {

    public static final Logger logger = LoggerFactory.getLogger(Recv.class);

    @RabbitListener(queues = "myqueue",containerFactory = "consumerBatchContainerFactory")
    public void listen(List<Message> amqpMessages) throws InterruptedException {
        logger.info("batch.queue.consumer 收到{}条message", amqpMessages.size());
        int i = 0;
        for (Message amqpMessage : amqpMessages) {
            logger.info("第{}条数据是: {}",++i,new String(amqpMessage.getBody()));
        }
    }

}
